﻿using System;
using Birkelund.QueryStrings.Tokens;
using NUnit.Framework;

namespace Birkelund.QueryStrings.Test
{
    public class ExtensionsTest
    {
        [TestCase(@"http://localhost/test/testFile.aspx?a=123", ExceptionNotificationBehaviour.ThrowException, Result = 123, TestName = "Real value - ThrowException")]
        [TestCase(@"http://localhost/test/testFile.aspx?a=123", ExceptionNotificationBehaviour.Silent, Result = 123, TestName = "Real value - Silent")]
        [TestCase(@"http://localhost/test/testFile.aspx?a=", ExceptionNotificationBehaviour.ThrowException, Result = null, TestName = "Empty value - ThrowException")]
        [TestCase(@"http://localhost/test/testFile.aspx?a=", ExceptionNotificationBehaviour.Silent, Result = null, TestName = "Empty value - Silent")]
        [TestCase(@"http://localhost/test/testFile.aspx", ExceptionNotificationBehaviour.ThrowException, Result = null, TestName = "No value - ThrowException")]
        [TestCase(@"http://localhost/test/testFile.aspx", ExceptionNotificationBehaviour.Silent, Result = null, TestName = "No value - Silent")]
        [TestCase(@"http://localhost/test/testFile.aspx?a=invalid", ExceptionNotificationBehaviour.ThrowException, ExpectedException = typeof(TokenParserException), TestName = "Invalid value - ThrowException")]
        [TestCase(@"http://localhost/test/testFile.aspx?a=invalid", ExceptionNotificationBehaviour.Silent, Result = default(int), TestName = "Invalid value - Silent")]
        public int? ReadNullIfEmptyTest(string input, ExceptionNotificationBehaviour behaviour)
        {
            Uri initialUrl = new Uri(input);

            IQueryStringToken<int> token = new ValueTypeToken<int>("a")
            {
                ExceptionNotificationBehaviour = behaviour
            };

            int? value = token.ReadNullIfEmpty(initialUrl);
            return value;
        }

        [Test, Ignore]
        public void EnsureThatReadNullIfEmptyIsVisibleFromInterface() { }
    }
}
